<?php
session_start();
header('Content-type:text/html;charset=utf-8');
//var_dump($_POST);
//var_dump($_SESSION);

    $title=$_POST['title'];
    $content=$_POST['content'];
    $uid=$_SESSION['user']['id'];
    $tid=$_POST['tid'];
    $rep=$_POST['rep'];
    $ctime=time();
    
    include('../../install/dbconfig.php');
    mysql_connect(DB_HOST,DB_USER,DB_PASSWD);
    mysql_select_db(DB_NAME);
    mysql_set_charset(DB_CHARSET);
    $SQL="insert into post (uid,tid,title,content,ctime,rep) values ('{$uid}','{$tid}','{$title}','{$content}','{$ctime}','{$rep}')";
    //echo $SQL;
    //exit;
    mysql_query($SQL);
    if(mysql_affected_rows()>0){
        
        //获取当前的积分
        $SQLF="select score from userDetail where id={$uid}";
        $resf=mysql_query($SQLF);
        $arr=mysql_fetch_assoc($resf);
        $score=$arr['score'];
        
        //给积分加1，给session赋值后，再写入数据库；
        $score=$score+2;
        $_SESSION['userDetail']['score']=$score;
        $SQLJ="update userDetail set score='{$score}' where id={$uid}";
        mysql_query($SQLJ);
        
    echo "<script>alert('发帖成功！');window.location.href='./list.php?pid={$_SESSION['list']['pid']}&id={$_SESSION['list']['id']}&fname={$_SESSION['list']['fname']}&bname={$_SESSION['list']['bname']}&imgName={$_SESSION['list']['imgName']}'</script>";
    }
    mysql_close();
?>
